home *** CD-ROM | disk | FTP | other *** search
/ Champak 64 / Volume 64 - JOGO DISK .iso / Games / the_best_every_day.swf / scripts / __Packages / ObstacleGenerator.as < prev    next >
Text File  |  2008-04-10  |  5KB  |  156 lines

  1. class ObstacleGenerator
  2. {
  3.    var ARRAY_OBSTACLE_TYPES = new Array("Bubbles","Bubbles","Bubbles","Banana","Banana","Banana","Gary","Gary");
  4.    function ObstacleGenerator(l_oTimeGeneratorSpeed)
  5.    {
  6.       this.setObject();
  7.       this.__set__time(l_oTimeGeneratorSpeed);
  8.    }
  9.    function update()
  10.    {
  11.       this.oTime.update();
  12.       if(this.oTime.__get__timeOut())
  13.       {
  14.          var _loc6_ = 0;
  15.          while(_loc6_ < 5)
  16.          {
  17.             var _loc3_ = undefined;
  18.             var _loc2_ = undefined;
  19.             var _loc4_ = 0;
  20.             do
  21.             {
  22.                _loc3_ = Math.floor(Math.random() * this.ARRAY_OBSTACLE_TYPES.length);
  23.                _loc2_ = this.ARRAY_OBSTACLE_TYPES[_loc3_];
  24.                _loc4_ = _loc4_ + 1;
  25.                if(_loc4_ > 25)
  26.                {
  27.                   break;
  28.                }
  29.             }
  30.             while(_loc4_ < 4 && (this.oObstacles[_loc2_].length == 0 || this.oObstacles[_loc2_].length == 1 && this.oObstacles[_loc2_][0].getActive()));
  31.             
  32.             if(_loc4_ < 4)
  33.             {
  34.                var _loc5_ = 0;
  35.                do
  36.                {
  37.                   _loc5_ = _loc5_ + 1;
  38.                   if(_loc5_ > 10)
  39.                   {
  40.                      break;
  41.                   }
  42.                   _loc3_ = Math.floor(Math.random() * this.oObstacles[_loc2_].length);
  43.                }
  44.                while(this.oObstacles[_loc2_][_loc3_].getActive());
  45.                
  46.             }
  47.             if(this.getDistanceBetween(this.oPatrick.mc,this.oObstacles[_loc2_][_loc3_]) > 350)
  48.             {
  49.                _loc6_ = 10;
  50.             }
  51.             _loc6_ = _loc6_ + 1;
  52.          }
  53.          this.oObstacles[_loc2_][_loc3_].setObstacle();
  54.          this.aActiveObstacles.push(this.oObstacles[_loc2_][_loc3_]);
  55.          this.reset();
  56.       }
  57.       this.Collide();
  58.    }
  59.    function getDistanceBetween(__movie1, __movie2)
  60.    {
  61.       var _loc1_ = Math.abs(__movie1._x - __movie2._x);
  62.       var _loc2_ = Math.abs(__movie1._y - __movie2._y);
  63.       return _loc1_ + _loc2_ * 3;
  64.    }
  65.    function addObstacle(l_mcObstacle, l_sType)
  66.    {
  67.       this.oObstacles[l_sType].push(l_mcObstacle);
  68.       if(l_sType == "Slobber")
  69.       {
  70.          this.aActiveObstacles.push(l_mcObstacle);
  71.       }
  72.    }
  73.    function removeObstacle(l_mcObstacle)
  74.    {
  75.       for(var _loc2_ in this.aActiveObstacles)
  76.       {
  77.          if(l_mcObstacle == this.aActiveObstacles[_loc2_])
  78.          {
  79.             this.aActiveObstacles.splice(_loc2_,1);
  80.          }
  81.       }
  82.    }
  83.    function reset()
  84.    {
  85.       var _loc4_ = this.oOriginalTime.__get__minutes();
  86.       var _loc3_ = this.oOriginalTime.__get__seconds() - Math.floor(_global.Pack.nLevel / 3);
  87.       if(_loc3_ < 5)
  88.       {
  89.          _loc3_ = 5;
  90.       }
  91.       this.oTime = new sarbakan.utils.Time(_loc4_,_loc3_);
  92.    }
  93.    function setObject()
  94.    {
  95.       var _loc2_ = undefined;
  96.       this.oObstacles = new Object();
  97.       for(_loc2_ in this.ARRAY_OBSTACLE_TYPES)
  98.       {
  99.          this.oObstacles[this.ARRAY_OBSTACLE_TYPES[_loc2_]] = new Array();
  100.       }
  101.       this.aActiveObstacles = new Array();
  102.    }
  103.    function Collide()
  104.    {
  105.       var _loc2_ = undefined;
  106.       this.oPatrick.trap(false);
  107.       if(this.oPatrick.bActive && this.oPatrick.sState == "Move")
  108.       {
  109.          for(_loc2_ in this.aActiveObstacles)
  110.          {
  111.             if(this.oPatrick.mc.mcDetector.hitTest(this.aActiveObstacles[_loc2_]))
  112.             {
  113.                if(this.aActiveObstacles[_loc2_].getType() != "Gary")
  114.                {
  115.                   this.oPatrick.trap(true,this.aActiveObstacles[_loc2_]);
  116.                }
  117.             }
  118.          }
  119.       }
  120.    }
  121.    function addTime(l_oTime)
  122.    {
  123.       this.oTime.addTime(l_oTime);
  124.    }
  125.    function set time(l_oTime)
  126.    {
  127.       this.oTime = l_oTime;
  128.       this.oOriginalTime = new sarbakan.utils.Time(l_oTime.__get__minutes(),l_oTime.__get__seconds());
  129.       var _loc3_ = l_oTime.__get__seconds() - Math.floor(_global.Pack.nLevel / 3);
  130.       if(_loc3_ < 5)
  131.       {
  132.          _loc3_ = 5;
  133.       }
  134.       trace("time between event = " + _loc3_);
  135.    }
  136.    function set patrick(l_oPatrick)
  137.    {
  138.       this.oPatrick = l_oPatrick;
  139.    }
  140.    function garyCollide()
  141.    {
  142.       var _loc2_ = undefined;
  143.       for(_loc2_ in this.aActiveObstacles)
  144.       {
  145.          if(this.aActiveObstacles[_loc2_].getType() == "Slobber")
  146.          {
  147.             if(this.oPatrick.mc._parent.gary.mcEdgeDetector.hitTest(this.aActiveObstacles[_loc2_]))
  148.             {
  149.                return false;
  150.             }
  151.          }
  152.       }
  153.       return true;
  154.    }
  155. }
  156.